#include "guiterm.hpp"

CommandPromptEdit::CommandPromptEdit(CommandPrompt *owner)
	:QLineEdit(owner)
{
	setPalette(*PaletteManager::activeInput());
	setFrame(false);
	setFont(config.font);
	this->owner = owner;
}

void CommandPromptEdit::keyPressEvent(QKeyEvent *event)
{
	if(owner->getWindow()->globalHotkey(event))
	{
		return;
	}
	if(event->key() == Qt::Key_Tab)
	{
		owner->tabComplete();
		event->accept();
	}
	else if(event->key() == Qt::Key_Up)
	{
		string newText = owner->history->up(text().toStdString());
		setText(newText.c_str());
		event->accept();
	}
	else if(event->key() == Qt::Key_Down)
	{
		string newText = owner->history->down(text().toStdString());
		setText(newText.c_str());
		event->accept();
	}
	else
	{
		QLineEdit::keyPressEvent(event);
	}
}

